<template>
  <div>
    <!-- 条件查询 -->
    <div class="head-container">
      <div>
        <!-- 搜索 -->
        <el-input
          v-model="crud.query.sourceDbName"
          clearable
          size="small"
          placeholder="源库名"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="crud.query.sourceTableName"
          clearable
          placeholder="源表名"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="crud.query.contrastDbName"
          clearable
          size="small"
          placeholder="比对库名"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="crud.query.contrastTableName"
          clearable
          placeholder="比对表名"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation :crud="crud" />
        <!-- 导出 -->
        <el-button
          :loading="downloadLoading"
          size="mini"
          class="filter-item"
          type="warning"
          icon="el-icon-download"
          @click="resultDownloadMethod"
        >导出</el-button>
      </div>
    </div>

    <el-table
      ref="table"
      :data="crud.data"
      border
      max-height="590px"
      style="width: 100%;"
      @selection-change="crud.selectionChangeHandler"
      @filter-change="crud.handleFilterChange"
    >
      <!-- 展开行时显示信息 -->
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" class="demo-table-expand-detail">
            <el-form-item label="源where条件">
              <span>{{ getSourceWhereCondition(props.row.whereCondition) }}</span>
            </el-form-item>
            <el-form-item label="目标where条件">
              <span>{{ getTargetWhereCondition(props.row.whereCondition) }}</span>
            </el-form-item>
            <el-form-item label="表是否存在">
              <span>{{ props.row.contrastListResultMessage['isCreateTable'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isFieldCount'] !== undefined" label="字段总数">
              <span>{{ props.row.contrastListResultMessage['isFieldCount'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isFieldName'] !== undefined" label="字段名称">
              <template>
                <el-table
                  v-if="verifyIsAllFieldMessage(props.row.contrastListResultMessage['isFieldName'])"
                  :data="JSON.parse(props.row.contrastListResultMessage['isFieldName'])"
                  style="width: 900px"
                  border
                >
                  <el-table-column prop="source" label="源字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.source }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="target" label="目标字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.target }}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
              <span v-if="!verifyIsAllFieldMessage(props.row.contrastListResultMessage['isFieldName'])">{{ props.row.contrastListResultMessage['isFieldName'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isContrastFieldType'] !== undefined" label="字段类型">
              <template>
                <el-table
                  v-if="verifyIsAllFieldMessage(props.row.contrastListResultMessage['isContrastFieldType'])"
                  :data="JSON.parse(props.row.contrastListResultMessage['isContrastFieldType'])"
                  style="width: 900px"
                  border
                >
                  <el-table-column prop="source" label="源字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.source }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="target" label="目标字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.target }}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
              <span v-if="!verifyIsAllFieldMessage(props.row.contrastListResultMessage['isContrastFieldType'])">{{ props.row.contrastListResultMessage['isContrastFieldType'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isContrastFieldLength'] !== undefined" label="字段长度">
              <template>
                <el-table
                  v-if="verifyIsAllFieldMessage(props.row.contrastListResultMessage['isContrastFieldLength'])"
                  :data="JSON.parse(props.row.contrastListResultMessage['isContrastFieldLength'])"
                  style="width: 900px"
                  border
                >
                  <el-table-column prop="source" label="源字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.source }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="target" label="目标字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.target }}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
              <span v-if="!verifyIsAllFieldMessage(props.row.contrastListResultMessage['isContrastFieldLength'])">{{ props.row.contrastListResultMessage['isContrastFieldLength'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isContrastFieldPrecision'] !== undefined" label="字段精度">
              <template>
                <el-table
                  v-if="verifyIsAllFieldMessage(props.row.contrastListResultMessage['isContrastFieldPrecision'])"
                  :data="JSON.parse(props.row.contrastListResultMessage['isContrastFieldPrecision'])"
                  style="width: 900px"
                  border
                >
                  <el-table-column prop="source" label="源字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.source }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="target" label="目标字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.target }}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
              <span v-if="!verifyIsAllFieldMessage(props.row.contrastListResultMessage['isContrastFieldPrecision'])">{{ props.row.contrastListResultMessage['isContrastFieldPrecision'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isContrastPartitionField'] !== undefined" label="分区字段">
              <span>{{ props.row.contrastListResultMessage['isContrastPartitionField'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isHasData'] !== undefined" label="有无数据">
              <span>{{ props.row.contrastListResultMessage['isHasData'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isStatisticsDataCount'] !== undefined" label="全表COUNT">
              <span>{{ props.row.contrastListResultMessage['isStatisticsDataCount'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isSumCharLength'] !== undefined" label="字符字段长度SUM">
              <template>
                <el-table
                  v-if="verifyIsAllFieldMessage(props.row.contrastListResultMessage['isSumCharLength'])"
                  :data="JSON.parse(props.row.contrastListResultMessage['isSumCharLength'])"
                  style="width: 900px"
                  border
                >
                  <el-table-column prop="source" label="源字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.source }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="target" label="目标字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.target }}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
              <span v-if="!verifyIsAllFieldMessage(props.row.contrastListResultMessage['isSumCharLength'])">{{ props.row.contrastListResultMessage['isSumCharLength'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isSumCharTrimLength'] !== undefined" label="字符字段长度TRIM后SUM">
              <template>
                <el-table
                  v-if="verifyIsAllFieldMessage(props.row.contrastListResultMessage['isSumCharTrimLength'])"
                  :data="JSON.parse(props.row.contrastListResultMessage['isSumCharTrimLength'])"
                  style="width: 900px"
                  border
                >
                  <el-table-column prop="source" label="源字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.source }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="target" label="目标字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.target }}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
              <span v-if="!verifyIsAllFieldMessage(props.row.contrastListResultMessage['isSumCharTrimLength'])">{{ props.row.contrastListResultMessage['isSumCharTrimLength'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isMaxCharLength'] !== undefined" label="字符字段长度MAX">
              <template>
                <el-table
                  v-if="verifyIsAllFieldMessage(props.row.contrastListResultMessage['isMaxCharLength'])"
                  :data="JSON.parse(props.row.contrastListResultMessage['isMaxCharLength'])"
                  style="width: 900px"
                  border
                >
                  <el-table-column prop="source" label="源字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.source }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="target" label="目标字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.target }}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
              <span v-if="!verifyIsAllFieldMessage(props.row.contrastListResultMessage['isMaxCharLength'])">{{ props.row.contrastListResultMessage['isMaxCharLength'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isStatisticsNumberSum'] !== undefined" label="数字字段SUM">
              <template>
                <el-table
                  v-if="verifyIsAllFieldMessage(props.row.contrastListResultMessage['isStatisticsNumberSum'])"
                  :data="JSON.parse(props.row.contrastListResultMessage['isStatisticsNumberSum'])"
                  style="width: 900px"
                  border
                >
                  <el-table-column prop="source" label="源字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.source }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="target" label="目标字段信息">
                    <template slot-scope="scope">
                      {{ scope.row.target }}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
              <span v-if="!verifyIsAllFieldMessage(props.row.contrastListResultMessage['isStatisticsNumberSum'])">{{ props.row.contrastListResultMessage['isStatisticsNumberSum'] }}</span>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['sumField'] !== undefined" label="指定字段SUM">
              <el-table
                :data="parseSumFields(props.row.contrastListResultMessage['sumField'])"
                border
                style="width: 900px"
              >
                <el-table-column prop="field" label="SUM字段名">
                  <template slot-scope="scope">
                    {{ scope.row.field }}
                  </template>
                </el-table-column>
                <el-table-column prop="message" label="比对结果">
                  <template slot-scope="scope">
                    {{ scope.row.message }}
                  </template>
                </el-table-column>
              </el-table>
            </el-form-item>
            <el-form-item v-if="props.row.contrastListResultMessage['isAllField'] !== undefined" label="全字段明细">
              <template>
                <el-table
                  v-if="verifyIsAllFieldMessage(props.row.contrastListResultMessage['isAllField'])"
                  :data="JSON.parse(props.row.contrastListResultMessage['isAllField'])"
                  style="width: 1050px"
                  border
                >
                  <el-table-column prop="fields" label="比对错误字段">
                    <template slot-scope="scope">
                      {{ scope.row.fields }}
                    </template>
                  </el-table-column>
                  <el-table-column prop="source,target" label="源/目标数据库数据">
                    <template slot-scope="scope">
                      {{ scope.row.source }}
                      <el-divider />
                      {{ scope.row.target }}
                    </template>
                  </el-table-column>
                </el-table>
              </template>
              <span v-if="!verifyIsAllFieldMessage(props.row.contrastListResultMessage['isAllField'])">{{ props.row.contrastListResultMessage['isAllField'] }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column prop="sourceDbName" label="源库名" :show-overflow-tooltip="true" min-width="110px" />
      <el-table-column prop="sourceTableName" label="源表名" :show-overflow-tooltip="true" min-width="170px" />
      <el-table-column prop="contrastDbName" label="对比库名" :show-overflow-tooltip="true" min-width="110px" />
      <el-table-column prop="contrastTableName" label="对比库名" :show-overflow-tooltip="true" min-width="170px" />
      <el-table-column prop="whereCondition" align="center" label="where条件">
        <template slot-scope="scope">
          <el-button
            type="text"
            size="mini"
            @click="whereConditionShow(scope.row.whereCondition)"
          >
            详情
          </el-button>
        </template>
      </el-table-column>
      <!-- 优先展示比对信息 -->
      <el-table-column
        prop="isCreateTable"
        label="表是否存在"
        align="center"
        width="100px"
        :filters="isCreateTableFilters"
        filter-placement="bottom-end"
        :filter-multiple="false"
        column-key="isCreateTable"
      >
        <template slot-scope="scope">
          <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isCreateTable')">
            {{ scope.row.contrastListResult['isCreateTable'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isCreateTable'] === 'FAIL' ? 'X' : '—' ) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="isFieldCount"
        label="字段总数"
        align="center"
        width="85px"
        :filters="isFieldCountFilters"
        filter-placement="bottom-end"
        :filter-multiple="false"
        column-key="isFieldCount"
      >
        <template slot-scope="scope">
          <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isFieldCount')">
            {{ scope.row.contrastListResult['isFieldCount'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isFieldCount'] === 'FAIL' ? 'X' : '—' ) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="isHasData"
        label="有无数据"
        align="center"
        width="85px"
        :filters="isHasDataFilters"
        filter-placement="bottom-end"
        :filter-multiple="false"
        column-key="isHasData"
      >
        <template slot-scope="scope">
          <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isHasData')">
            {{ scope.row.contrastListResult['isHasData'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isHasData'] ==='FAIL' ? 'X' : '—' ) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="isStatisticsDataCount"
        label="全表COUNT"
        align="center"
        width="100px"
        :filters="isStatisticsDataCountFilters"
        filter-placement="bottom-end"
        :filter-multiple="false"
        column-key="isStatisticsDataCount"
      >
        <template slot-scope="scope">
          <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isStatisticsDataCount')">
            {{ scope.row.contrastListResult['isStatisticsDataCount'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isStatisticsDataCount'] ==='FAIL' ? 'X' : '—' ) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="isAllField"
        label="全字段明细"
        align="center"
        width="100px"
        :filters="isAllFieldFilters"
        filter-placement="bottom-end"
        :filter-multiple="false"
        column-key="isAllField"
      >
        <template slot-scope="scope">
          <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isAllField')">
            {{ scope.row.contrastListResult['isAllField'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isAllField'] ==='FAIL' ? 'X' : '—' ) }}
          </el-tag>
        </template>
      </el-table-column>
      <!-- 其他比对 -->
      <el-table-column label="表结构对比" align="center">
        <el-table-column prop="isFieldName" label="字段名称" align="center">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isFieldName')">
              {{ scope.row.contrastListResult['isFieldName'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isFieldName'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="isContrastPartitionField" label="分区字段" align="center">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isContrastPartitionField')">
              {{ scope.row.contrastListResult['isContrastPartitionField'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isContrastPartitionField'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="isContrastFieldType" label="字段类型" align="center">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isContrastFieldType')">
              {{ scope.row.contrastListResult['isContrastFieldType'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isContrastFieldType'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="isContrastFieldLength" label="字段长度" align="center">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isContrastFieldLength')">
              {{ scope.row.contrastListResult['isContrastFieldLength'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isContrastFieldLength'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="isContrastFieldPrecision" label="字段精度" align="center">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isContrastFieldPrecision')">
              {{ scope.row.contrastListResult['isContrastFieldPrecision'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isContrastFieldPrecision'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="数据统计对比" align="center">

        <el-table-column prop="isSumCharLength" label="字符字段长度SUM" align="center" :show-overflow-tooltip="true" min-width="130px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isSumCharLength')">
              {{ scope.row.contrastListResult['isSumCharLength'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isSumCharLength'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="isSumCharTrimLength" label="字符字段长度TRIM后SUM" align="center" :show-overflow-tooltip="true" min-width="180px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isSumCharTrimLength')">
              {{ scope.row.contrastListResult['isSumCharTrimLength'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isSumCharTrimLength'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="isMaxCharLength" label="字符字段长度MAX" align="center" :show-overflow-tooltip="true" min-width="130px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isMaxCharLength')" :show-overflow-tooltip="true" min-width="130px">
              {{ scope.row.contrastListResult['isMaxCharLength'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isMaxCharLength'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="isStatisticsNumberSum" label="数字字段SUM" align="center" :show-overflow-tooltip="true" min-width="130px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isStatisticsNumberSum')">
              {{ scope.row.contrastListResult['isStatisticsNumberSum'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isStatisticsNumberSum'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="removeRepeatCountField" label="指定字段去重COUNT" align="center" :show-overflow-tooltip="true" min-width="140px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'removeRepeatCountField')">
              {{ scope.row.contrastListResult['removeRepeatCountField'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['removeRepeatCountField'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="groupCountField" label="指定字段分组COUNT" align="center" :show-overflow-tooltip="true" min-width="140px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'groupCountField')">
              {{ scope.row.contrastListResult['groupCountField'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['groupCountField'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="countField" label="指定字段COUNT" align="center" :show-overflow-tooltip="true" min-width="130px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'countField')">
              {{ scope.row.contrastListResult['countField'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['countField'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="sumField" label="指定字段SUM" align="center" :show-overflow-tooltip="true" min-width="130px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'sumField')">
              {{ scope.row.contrastListResult['sumField'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['sumField'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="trimField" label="指定字段TRIM" align="center" :show-overflow-tooltip="true" min-width="130px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'trimField')">
              {{ scope.row.contrastListResult['trimField'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['trimField'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column label="少量数据对比" align="center">
        <el-table-column prop="isCharNullToEmpty" label="字段NULL转为空" align="center" :show-overflow-tooltip="true" min-width="130px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isCharNullToEmpty')">
              {{ scope.row.contrastListResult['isCharNullToEmpty'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isCharNullToEmpty'] === 'FAIL' ? 'X' : '—') }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="isNumberNullToZero" label="数值NULL转为0" align="center" :show-overflow-tooltip="true" min-width="130px">
          <template slot-scope="scope">
            <el-tag size="medium" :type="dynamicContrastStatus(scope.row, 'isNumberNullToZero')">
              {{ scope.row.contrastListResult['isNumberNullToZero'] === 'SUCCESS' ? '√' : (scope.row.contrastListResult['isNumberNullToZero'] ==='FAIL' ? 'X' : '—' ) }}
            </el-tag>
          </template>
        </el-table-column>
      </el-table-column>
    </el-table>
    <pagination />
    <!--where条件 弹窗-->
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :before-close="whereConditionClose"
      :visible.sync="whereConditionFlag"
      title="where条件"
      width="800px"
    >
      <el-form label-width="130px" style="margin: 5px 0 0 20px">
        <el-form-item label="源where条件">
          <el-input v-model="sourceWhereCondition" type="textarea" :rows="5" style="width: 540px;" disabled />
        </el-form-item>
        <el-form-item label="目标where条件">
          <el-input v-model="targetWhereCondition" type="textarea" :rows="5" style="width: 540px;" disabled />
        </el-form-item>
      </el-form>

    </el-dialog>
  </div>
</template>

<script>
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import crudDown from '@/mixins/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/expand/data/contrast/task/CRUD.operation.vue'
import pagination from '@crud/Pagination'
import contrastTaskApi from '@/api/data/contrast/contrastTask'

const defaultCrud = CRUD({
  title: '跨库比对结果',
  url: 'api/cross/db/contrast/list/result',
  crudMethod: { ...contrastTaskApi }
})
const defaultForm = {}

export default {
  // eslint-disable-next-line vue/no-unused-components
  components: { crudOperation, rrOperation, pagination },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(), crudDown],
  props: {
    contrastTaskPkId: {
      required: true,
      type: String
    },
    contrastRunLogPkId: {
      required: true,
      type: String
    }
  },
  data() {
    return {
      data: [],
      sourceWhereCondition: '',
      targetWhereCondition: '',
      whereConditionFlag: false,
      isCreateTableFilters: [],
      isFieldCountFilters: [],
      isHasDataFilters: [],
      isStatisticsDataCountFilters: [],
      isAllFieldFilters: []
    }
  },
  watch: {
  },
  created() {
    // 重置搜索
    this.crud.resetQuery()
  },
  methods: {
    resultDownloadMethod() {
      this.url = 'api/cross/db/contrast/list/result'
      this.params.taskPkId = this.contrastTaskPkId
      this.params.runLogPkId = this.contrastRunLogPkId
      this.params.size = 1000
      this.downloadMethod()
    },
    [CRUD.HOOK.beforeRefresh](crud) {
      crud.query.taskPkId = this.contrastTaskPkId
      crud.query.runLogPkId = this.contrastRunLogPkId
    },
    // 动态显示对比情况
    dynamicContrastStatus(row, type) {
      if (row.contrastListResult[type] === 'SUCCESS') {
        return 'success'
      } else if (row.contrastListResult[type] === 'FAIL') {
        return 'danger'
      } else {
        return 'info'
      }
    },
    // where条件 关闭
    whereConditionClose() {
      this.whereConditionFlag = false
    },
    // where条件 展示
    whereConditionShow(whereCondition) {
      this.sourceWhereCondition = ''
      this.targetWhereCondition = ''
      if (whereCondition !== undefined && whereCondition !== null && whereCondition !== '') {
        this.sourceWhereCondition = JSON.parse(whereCondition).sourceWhereCondition
        this.targetWhereCondition = JSON.parse(whereCondition).targetWhereCondition
      }
      this.whereConditionFlag = true
    },
    getSourceWhereCondition(whereCondition) {
      if (whereCondition !== undefined && whereCondition !== null && whereCondition !== '') {
        return JSON.parse(whereCondition).sourceWhereCondition
      }
      return '无'
    },
    getTargetWhereCondition(whereCondition) {
      if (whereCondition !== undefined && whereCondition !== null && whereCondition !== '') {
        return JSON.parse(whereCondition).targetWhereCondition
      }
      return '无'
    },
    verifyIsAllFieldMessage(val) {
      return val !== undefined && val.startsWith('[')
    },
    parseSumFields(data) {
      if (!data) return []
      return data.split(',').map(part => {
        const [field, ...message] = part.split('-')
        return {
          field: field.trim(), message: message.join('-').trim()
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .demo-table-expand-detail {
    font-size: 0;
  }
  .demo-table-expand-detail label {
    width: 120px;
    color: #99a9bf;
  }
  .demo-table-expand-detail .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>
